{% load static %}
<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>热门视频 - ShortVid</title>
  <!-- 与首页一致的依赖与样式 -->
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
  <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap" rel="stylesheet">
  <link rel="stylesheet" href="{% static 'home/home.css' %}">
  <!-- 热门页自己的补充样式（可选） -->
  <link rel="stylesheet" href="{% static 'home/hot.css' %}">
</head>
<body>
  <!-- 与首页一致的导航栏 -->
  <nav class="navbar navbar-expand-lg navbar-light bg-white shadow-sm py-3">
    <div class="container">
      <a class="navbar-brand" href="{% url 'home' %}">
        <i class="fas fa-play-circle me-2"></i>ShortVid
      </a>
      <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
        <span class="navbar-toggler-icon"></span>
      </button>
      <div class="collapse navbar-collapse" id="navbarNav">
        <ul class="navbar-nav me-auto">
          <li class="nav-item"><a class="nav-link" href="{% url 'home' %}">首页</a></li>
          <li class="nav-item"><a class="nav-link" href="{% url 'discover' %}">发现</a></li>
          <li class="nav-item"><a class="nav-link active" href="{% url 'hot' %}">热门</a></li>
          {% if user.is_authenticated %}
            <li class="nav-item"><a class="nav-link" href="{% url 'following' %}">关注</a></li>
          {% else %}
            <li class="nav-item"><a class="nav-link" href="{% url 'login' %}?next={% url 'following' %}" onclick="return remindLogin()">关注</a></li>
          {% endif %}
        </ul>
        <div class="d-flex align-items-center">
          {% if user.is_authenticated %}
            <a href="{% url 'profile' %}" class="d-flex align-items-center me-3 text-decoration-none">
              <div class="user-avatar">{{ user.username|first|upper }}</div>
              <span class="user-greeting ms-2">你好, {{ user.username }}!</span>
            </a>
            <a href="{% url 'logout' %}" class="btn btn-outline-primary btn-sm">注销</a>
          {% else %}
            <a href="{% url 'login' %}" class="btn btn-outline-primary me-2">登录</a>
            <a href="{% url 'register' %}" class="btn btn-primary">注册</a>
          {% endif %}
        </div>
      </div>
    </div>
  </nav>

  <!-- 页面主体内容 -->
  <main class="py-5">
    <div class="container">
      <h2 class="section-title mb-4">热门视频</h2>
      <section id="video-grid" class="video-grid" aria-live="polite"></section>
      <div id="loading" class="loading mt-3" hidden>加载中…</div>
      <div id="error" class="error mt-3" hidden>加载失败，请稍后重试。</div>
    </div>
  </main>

  <!-- 与首页一致的页脚 -->
  <footer class="footer">
    <div class="container">
      <div class="row">
        <div class="col-lg-4 mb-4">
          <h4 class="mb-4"><i class="fas fa-play-circle me-2"></i>ShortVid</h4>
          <p>发现精彩短视频，记录美好生活瞬间。加入我们的社区，一起创作、分享和发现。</p>
          <div class="social-icons mt-4">
            <a href="#"><i class="fab fa-weibo"></i></a>
            <a href="#"><i class="fab fa-weixin"></i></a>
            <a href="#"><i class="fab fa-qq"></i></a>
            <a href="#"><i class="fab fa-github"></i></a>
          </div>
        </div>
        <div class="col-lg-2 col-md-6 mb-4">
          <h5 class="mb-4">平台</h5>
          <ul class="list-unstyled">
            <li class="mb-2"><a href="{% url 'home' %}">首页</a></li>
            <li class="mb-2"><a href="{% url 'discover' %}">发现</a></li>
            <li class="mb-2"><a href="{% url 'hot' %}">热门</a></li>
            {% if user.is_authenticated %}
              <li class="mb-2"><a href="{% url 'following' %}">关注</a></li>
            {% else %}
              <li class="mb-2"><a href="{% url 'login' %}?next={% url 'following' %}" onclick="return remindLogin()">关注</a></li>
            {% endif %}
          </ul>
        </div>
        <div class="col-lg-2 col-md-6 mb-4">
          <h5 class="mb-4">帮助</h5>
          <ul class="list-unstyled">
            <li class="mb-2"><a href="#">帮助中心</a></li>
            <li class="mb-2"><a href="#">使用指南</a></li>
            <li class="mb-2"><a href="#">社区准则</a></li>
            <li class="mb-2"><a href="#">联系我们</a></li>
          </ul>
        </div>
        <div class="col-lg-4 mb-4">
          <h5 class="mb-4">订阅我们的资讯</h5>
          <p>获取最新功能和活动信息</p>
          <div class="input-group mb-3">
            <input type="email" class="form-control" placeholder="请输入您的邮箱">
            <button class="btn btn-primary" type="button">订阅</button>
          </div>
        </div>
      </div>
      <hr class="my-4">
      <div class="text-center"><p>&copy; 2023 ShortVid 短视频平台. 保留所有权利.</p></div>
    </div>
  </footer>

  <!-- JS -->
  <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
  <script src="{% static 'home/home.js' %}"></script>
  <!-- 登录上下文变量，供 hot.js 使用 -->
  <script>
    window.CURRENT_USER = "{{ user.username|default:'' }}";
    window.IS_AUTH = "{{ user.is_authenticated|yesno:'true,false' }}" === 'true';
    window.redirectToLogin = function(){
      location.href = "{% url 'login' %}?next=" + encodeURIComponent(location.pathname + location.search);
    };
  </script>
  <script src="{% static 'home/hot.js' %}"></script>
  <script>
    function remindLogin(){
      alert('请先登录后查看关注内容');
      return true;
    }
  </script>

  <style>
  /* 小内联兜底样式，完整样式在 hot.css */
  .video-grid{display:grid;gap:16px;grid-template-columns:repeat(auto-fill,minmax(240px,1fr));}
  .video-card{border:1px solid #e5e7eb;border-radius:8px;overflow:hidden;background:#fff}
  .video-meta{padding:8px 12px;font-size:14px;color:#374151}
  .video-actions{display:flex;gap:8px;padding:8px 12px;border-top:1px solid #e5e7eb}
  .video-actions button{border:1px solid #d1d5db;background:#fff;border-radius:999px;padding:6px 10px;font-size:13px;color:#374151;cursor:pointer}
  .video-actions button:hover{background:#f3f4f6}
  video{width:100%;height:360px;object-fit:cover;background:#000}
  </style>
</body>
</html>